package com.chat.datea.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chat.datea.R;
import com.chat.datea.bean.greendao.Collect;
import com.chat.datea.bean.greendao.CollectDao;
import com.chat.datea.bean.local_music.LocalMusicEntity;
import com.chat.datea.utils.daosingleton.DaoSingleton;

import java.util.ArrayList;

/**
 * Created by dllo on 15/11/3.
 */
public class HistoryAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<LocalMusicEntity> content;
    private CollectDao collectDao;
    private Collect collect;
    private   ArrayList<Collect> collects ;
    public HistoryAdapter(Context c){
        context = c;
        collectDao = DaoSingleton.getInstance().getCollectDao();
        collects  = (ArrayList<Collect>) collectDao.queryBuilder().where(CollectDao.Properties.Want.eq("播放记录")).list();
    }

    @Override
    public int getCount() {
        return collects != null && collects.size() > 0 ? collects.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return collects != null && collects.size() > 0 ? collects.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.downloder_item, null);
            holder.down_songName = (TextView) convertView.findViewById(R.id.down_songName);
            holder.down_singer = (TextView) convertView.findViewById(R.id.down_singer);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }

        //设置组件
        holder.down_songName.setText(collects.get(position).getName());
        holder.down_singer.setText(collects.get(position).getSinger());

        return convertView;
    }
    static class ViewHolder{
        private TextView down_songName,down_singer;
    }
}
